document.querySelector('.create-form')
    .addEventListener('submit', function (event) {
        event.preventDefault();
        const url = '/api/topic';
        fetch(`${url}`, {
            method: 'post',
            headers: new Headers({
                'Content-Type': 'application/json',
                'Authorization': `Bearer ${localStorage.getItem('token')}`
            }),
            body: xss(JSON.stringify(serializeJSON(document.querySelector('.create-form'))))
        })
            .then((res) => {
                return res.text();
            })
            .then((res) => {
                const requestJSON = JSON.parse(res);
                if (requestJSON.ok) {
                    alert(requestJSON.msg);
                } else {
                    alert(requestJSON.msg);
                }
            });
    });